libxl: Fix error handling in libxl_userdata_unlink
authorIan Jackson <ian.jackson@eu.citrix.com>
Wed, 24 Sep 2014 14:22:08 +0000 (15:22 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Wed, 8 Oct 2014 10:51:37 +0000 (11:51 +0100)
commit9fe1ab70752d81a65b2a1492c46d9119438c0e9e
tree9ffad8af71e91581a7410bb5092d57d8923934d6
parentf9b87b670cb2757d2f537f38f836deae4dc63fb8
libxl: Fix error handling in libxl_userdata_unlink

Previously:
  * rc would not be set before leaving the function, with the
    result that an uninitialised value would be returned
  * failures of libxl__userdata_path would result in a NULL dereference
  * failures of unlink() would not be usefully logged

This appears to be due to an attempt to avoid having to repeat the
call to libxl__unlock_domain_userdata by informally sharing parts of
the success and failure paths.

Change to use the canonical error-handling style:
  * Initialise lock to 0.
  * Do the unlock in the `out' section - always attempt to unlock
    lock if it is non-0.
  * Explicitly set rc and `goto out' on all error paths, even
    those right at the end of the function.
  * Add an error check for filename = libxl__userdata_path(...);

Coverity-ID: 12402371240235.
CC: Wei Liu <wei.liu2@citrix.com>
CC: coverity@xenproject.org
Reviewed-by: Andrew Cooper<andrew.cooper3@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
tools/libxl/libxl_dom.c